<template>
  <div id="popupzc" class="container">
    <div class="popupzc">
        <button type="button" class="closeone" @click="closeZc">x</button>
        <div class="body">
            <div class="biaoyuzc">欢迎注册</div>
            <div class="tishiti"><span v-show="zctShow">提示：{{ zctishi }}</span></div>
            <div class="boxint">
                <div class="img"><img class="imgic" src="../../assets/img/phone.png" alt=""></div>
                <div class="val"><input class="inptzc" type="text" placeholder='请输入手机号码' v-model="zcform.mobile"></div>
            </div>
            <div class="boxint">
                <div class="img"><img class="imgic" src="../../assets/img/yanzhengma.png" alt=""></div>
                <div class="val"><input class="inptzc" type="text" placeholder='请输入验证码' v-model="zcform.code"></div>
                <span class="yzm"><button class="yzmb" :class="{disable: zcform.mobile.length !== 11}" :disabled="zcform.mobile.length !== 11" @click="huoquyzm(),getCode()" v-show="show">获取验证码</button></span>
                <span class="yzm"><button class="yzmb" v-show="!show">{{ count }}</button></span>
            </div>
            <div class="boxint">
                <div class="img"><img class="imgic" src="../../assets/img/mima.png" alt=""></div>
                <div class="val"><input class="inptzc" type="password" placeholder='请设置密码' v-model="zcform.password"></div>
            </div>
            <!-- <div class="mima">找回密码</div> -->
            <div class="zcbtn pointer" @click="zhuceform">注册</div>
            <!-- <div class="tishi" style="font-size:3px;">提示：密码长度12~30位，不能以"/"开头，至少包含三项（1.小写字母a~z,2.大写字母A~z,数字0~9），不包括用户名</div> -->
        </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'popupzc',
  data() {
      return {
        show: true,
        count: '',
        timer: null,
        zctShow:false,
        zctishi:'',
        zcform: {
            mobile:'',
            updateType:'0',
            code:'',
            password:'',
            parentId:''
          }
      }
  },
  methods:{
    closeZc (){
      this.$emit('closeZc')
    },
    async huoquyzm() {
        var hqyzm = new FormData()
        hqyzm.set('mobile',this.zcform.mobile)
        hqyzm.set('updateType',this.zcform.updateType)
        const { data: res } = await this.$http.post('/app/user/sendVercode.do',hqyzm)
        console.log(res)
        if (res.code !== 0) return console.log('获取验证码失败')
        console.log('获取验证码成功')
    },
    async zhuceform() {
        var zc = new FormData()
        zc.set('mobile',this.zcform.mobile)
        zc.set('code',this.zcform.code)
        zc.set('password',this.zcform.password)
        zc.set('parentId',this.zcform.parentId)
        // const data = await this.$http.post('/app/user/sendVercode.do',`mobile=${this.zcform.mobile}&updateType=${this.zcform.updateType}`)
        const { data: res } = await this.$http.post('app/user/registerUser.do',zc)
        console.log(res)
        if (res.code !== 0){
            this.zctShow = true
          this.zctishi = res.msg
          var _that = this
          setTimeout(function(){
            _that.zctShow =false
          },3000);
        }else {
            console.log('注册成功')
            this.closeZc()
            this.$router.push({
        name:'home',
        query: {
          sutankuang: true,
          msg:'注册成功，请登录'
        }
      })
        }
    },
     getCode(){
     const TIME_COUNT = 60;
     if (!this.timer) {
       this.count = TIME_COUNT;
       this.show = false;
       this.timer = setInterval(() => {
       if (this.count > 0 && this.count <= TIME_COUNT) {
         this.count--;
        } else {
         this.show = true;
         clearInterval(this.timer);
         this.timer = null;
        }
       }, 1000)
      }
   }  
  }

}
</script>

<style>
  .container {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .popupzc {
    background: #FFFFFF;
    height: 420px;
    width: 400px;
  }
  .biaoyuzc {
      font-size: 20px;
      font-weight: bold;
  }
  .closeone {
      width: 30px;
      height: 30px;
      font-size: 25px;
      color: #999999;
      background-color: #fff;
      border: 0;
      position: relative;
      left: 360px;
      top: 10px;
  }
  .body {
      width: 100%;
      height: 410px;
      padding: 15px;
  }
  .tishi {
      width: 90%;
      height: 20px;
      margin-top: 20px;
  }
  .boxint {
      position: relative;
      height: 40px;
      width: 360px;
      background-color: #F6F6F6;
      margin-top: 25px;
  }
  .mima {
      position: relative;
      margin-top: 10px;
      left: 295px;
      color: #3C87CF;
  }
  .zcbtn {
      margin-top: 20px;
      height: 40px;
      width: 360px;
      background-color: #FF8B19;
      line-height: 40px;
      text-align:center;
      color: #fff;
      border-radius: 25px;
  }
  .img {
      position: absolute;
      width: 40px;
      height: 40px;
      line-height: 40px;
      top: 7px;
      left: 20px;
  }
  .imgic {
      width: 20px;
      height: 25px;
  }
  .val {
      position: absolute;
      left: 60px;
      height: 40px;
      line-height: 40px;
  }
  .inptzc {
      height: 32px;
      background:  #F6F6F6;
      border: 0;
      outline: none;
  }
  .yzm {
      position: absolute;
      line-height: 40px;
      right: 20px;
  }
  .yzmb {
      height: 40px;
      border: 0;
      background-color:#FAFAFA;
  }
</style>